package com.lkd.service;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

//@RunWith(SpringRunner.class)
//@SpringBootTest
public class CompleteTableFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> aFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(5000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 1;
        });

        CompletableFuture<Integer> bFuture = CompletableFuture.supplyAsync(() -> {

            try {
                Thread.sleep(6000);

            } catch (Exception e) {
                e.printStackTrace();
            }
            return 2;
        });

        CompletableFuture<Integer> cFuture = CompletableFuture.supplyAsync(() -> {
            //System.out.println(111);
            try {

                Thread.sleep(7000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 3;
        });

        //并行处理
        CompletableFuture.allOf(aFuture,bFuture,cFuture).join();
        Integer a = aFuture.get();
        Integer b = bFuture.get();
        Integer c = cFuture.get();
        System.out.println(a+" "+b+" "+c);
    }


}
